<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="支付人id支付来源" prop="payUserId">
      <el-input v-model="dataForm.payUserId" placeholder="支付人id支付来源"></el-input>
    </el-form-item>
    <el-form-item label="接收人id 收入、支出都存储这个" prop="receiveUserId">
      <el-input v-model="dataForm.receiveUserId" placeholder="接收人id 收入、支出都存储这个"></el-input>
    </el-form-item>
    <el-form-item label="用户收支金额，单位分正为收负为支" prop="userFund">
      <el-input v-model="dataForm.userFund" placeholder="用户收支金额，单位分正为收负为支"></el-input>
    </el-form-item>
    <el-form-item label="查看枚举类UserFundModeEnum" prop="modeType">
      <el-input v-model="dataForm.modeType" placeholder="查看枚举类UserFundModeEnum"></el-input>
    </el-form-item>
    <el-form-item label="模块id //直播对应直播房间主键id" prop="modeId">
      <el-input v-model="dataForm.modeId" placeholder="模块id //直播对应直播房间主键id"></el-input>
    </el-form-item>
    <el-form-item label="交易订单号" prop="tradeNumber">
      <el-input v-model="dataForm.tradeNumber" placeholder="交易订单号"></el-input>
    </el-form-item>
    <el-form-item label="第三方交易数据主键id" prop="pingxxId">
      <el-input v-model="dataForm.pingxxId" placeholder="第三方交易数据主键id"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="支付状态 0：发起支付 2：支付成功" prop="payState">
      <el-input v-model="dataForm.payState" placeholder="支付状态 0：发起支付 2：支付成功"></el-input>
    </el-form-item>
    <el-form-item label="1微信app2支付宝app3余额支付4ios内购" prop="payType">
      <el-input v-model="dataForm.payType" placeholder="1微信app2支付宝app3余额支付4ios内购"></el-input>
    </el-form-item>
    <el-form-item label="用于检索，收入和支出会生成2条记录，收入时为收入用户id支出时为支出用户id" prop="searchUserid">
      <el-input v-model="dataForm.searchUserid" placeholder="用于检索，收入和支出会生成2条记录，收入时为收入用户id支出时为支出用户id"></el-input>
    </el-form-item>
    <el-form-item label="搜索模块分类1提现2打赏3红包4金币5活动赚取6转盘" prop="searchCategory">
      <el-input v-model="dataForm.searchCategory" placeholder="搜索模块分类1提现2打赏3红包4金币5活动赚取6转盘"></el-input>
    </el-form-item>
    <el-form-item label=" 交易前余额余额  金钱单位为分，金币单位为个" prop="balanceBefroe">
      <el-input v-model="dataForm.balanceBefroe" placeholder=" 交易前余额余额  金钱单位为分，金币单位为个"></el-input>
    </el-form-item>
    <el-form-item label="账户余额  金钱单位为分，金币单位为个" prop="balanceAfter">
      <el-input v-model="dataForm.balanceAfter" placeholder="账户余额  金钱单位为分，金币单位为个"></el-input>
    </el-form-item>
    <el-form-item label="扩展字段，存json数据" prop="extnd">
      <el-input v-model="dataForm.extnd" placeholder="扩展字段，存json数据"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="支付时间" prop="payTime">
      <el-input v-model="dataForm.payTime" placeholder="支付时间"></el-input>
    </el-form-item>
    <el-form-item label="状态 1：正常 0：删除" prop="state">
      <el-input v-model="dataForm.state" placeholder="状态 1：正常 0：删除"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          payUserId: '',
          receiveUserId: '',
          userFund: '',
          modeType: '',
          modeId: '',
          tradeNumber: '',
          pingxxId: '',
          createTime: '',
          payState: '',
          payType: '',
          searchUserid: '',
          searchCategory: '',
          balanceBefroe: '',
          balanceAfter: '',
          extnd: '',
          updateTime: '',
          payTime: '',
          state: ''
        },
        dataRule: {
          payUserId: [
            { required: true, message: '支付人id支付来源不能为空', trigger: 'blur' }
          ],
          receiveUserId: [
            { required: true, message: '接收人id 收入、支出都存储这个不能为空', trigger: 'blur' }
          ],
          userFund: [
            { required: true, message: '用户收支金额，单位分正为收负为支不能为空', trigger: 'blur' }
          ],
          modeType: [
            { required: true, message: '查看枚举类UserFundModeEnum不能为空', trigger: 'blur' }
          ],
          modeId: [
            { required: true, message: '模块id //直播对应直播房间主键id不能为空', trigger: 'blur' }
          ],
          tradeNumber: [
            { required: true, message: '交易订单号不能为空', trigger: 'blur' }
          ],
          pingxxId: [
            { required: true, message: '第三方交易数据主键id不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          payState: [
            { required: true, message: '支付状态 0：发起支付 2：支付成功不能为空', trigger: 'blur' }
          ],
          payType: [
            { required: true, message: '1微信app2支付宝app3余额支付4ios内购不能为空', trigger: 'blur' }
          ],
          searchUserid: [
            { required: true, message: '用于检索，收入和支出会生成2条记录，收入时为收入用户id支出时为支出用户id不能为空', trigger: 'blur' }
          ],
          searchCategory: [
            { required: true, message: '搜索模块分类1提现2打赏3红包4金币5活动赚取6转盘不能为空', trigger: 'blur' }
          ],
          balanceBefroe: [
            { required: true, message: ' 交易前余额余额  金钱单位为分，金币单位为个不能为空', trigger: 'blur' }
          ],
          balanceAfter: [
            { required: true, message: '账户余额  金钱单位为分，金币单位为个不能为空', trigger: 'blur' }
          ],
          extnd: [
            { required: true, message: '扩展字段，存json数据不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          payTime: [
            { required: true, message: '支付时间不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '状态 1：正常 0：删除不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/simida/userfundlog/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.payUserId = data.userFundLog.payUserId
                this.dataForm.receiveUserId = data.userFundLog.receiveUserId
                this.dataForm.userFund = data.userFundLog.userFund
                this.dataForm.modeType = data.userFundLog.modeType
                this.dataForm.modeId = data.userFundLog.modeId
                this.dataForm.tradeNumber = data.userFundLog.tradeNumber
                this.dataForm.pingxxId = data.userFundLog.pingxxId
                this.dataForm.createTime = data.userFundLog.createTime
                this.dataForm.payState = data.userFundLog.payState
                this.dataForm.payType = data.userFundLog.payType
                this.dataForm.searchUserid = data.userFundLog.searchUserid
                this.dataForm.searchCategory = data.userFundLog.searchCategory
                this.dataForm.balanceBefroe = data.userFundLog.balanceBefroe
                this.dataForm.balanceAfter = data.userFundLog.balanceAfter
                this.dataForm.extnd = data.userFundLog.extnd
                this.dataForm.updateTime = data.userFundLog.updateTime
                this.dataForm.payTime = data.userFundLog.payTime
                this.dataForm.state = data.userFundLog.state
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/simida/userfundlog/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'payUserId': this.dataForm.payUserId,
                'receiveUserId': this.dataForm.receiveUserId,
                'userFund': this.dataForm.userFund,
                'modeType': this.dataForm.modeType,
                'modeId': this.dataForm.modeId,
                'tradeNumber': this.dataForm.tradeNumber,
                'pingxxId': this.dataForm.pingxxId,
                'createTime': this.dataForm.createTime,
                'payState': this.dataForm.payState,
                'payType': this.dataForm.payType,
                'searchUserid': this.dataForm.searchUserid,
                'searchCategory': this.dataForm.searchCategory,
                'balanceBefroe': this.dataForm.balanceBefroe,
                'balanceAfter': this.dataForm.balanceAfter,
                'extnd': this.dataForm.extnd,
                'updateTime': this.dataForm.updateTime,
                'payTime': this.dataForm.payTime,
                'state': this.dataForm.state
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
